﻿using System;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Web.UI.WebControls;

using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using Microsoft.Reporting.WebForms;
using Excel = Microsoft.Office.Interop.Excel;

namespace dcwj
{
    public partial class jsnlPage : System.Web.UI.Page
    {
        private String M_CONSTR = ConfigurationManager.ConnectionStrings["dcwjConnectionString"].ToString();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {

                    int n = Int32.Parse(Request["tid"].ToString());

                    Database objDB = new SqlDatabase(M_CONSTR);
                    DataSet dsAll = objDB.ExecuteDataSet(CommandType.Text, @"select 
        a.执行,
        b.技巧,
        c.态度,
        d.能力
        from

        (SELECT 
        avg(cast (QAnswer as decimal)) as 执行
          FROM Table_RESULT
        where paperid in(select paperid from table_paper where teacherid=" + n.ToString() + @" and PaperClassID=2) and Qid in(1,2,3,4,5,6,7,8)) as a,

        (SELECT 
        avg(cast (QAnswer as decimal)) as 技巧
          FROM Table_RESULT
        where paperid  in(select paperid from table_paper where teacherid = " + n.ToString() + @" and PaperClassID=2) and Qid in(9,10,11,12,13,14,15)) as b,

        (SELECT 
        avg(cast (QAnswer as decimal)) as 态度
          FROM Table_RESULT
        where paperid in(select paperid from table_paper where teacherid=" + n.ToString() + @" and PaperClassID=2) and Qid in(16,17,18)) as c,

        (SELECT 
        avg(cast (QAnswer as decimal)) as 能力
          FROM Table_RESULT
        where paperid  in(select paperid from table_paper where teacherid=" + n.ToString() + @" and PaperClassID=2  ) and Qid in(19,20)) as d");



                    DataSet dsAllAVG = objDB.ExecuteDataSet(CommandType.Text, @"select 
        a.执行,
        b.技巧,
        c.态度,
        d.能力
        from

        (SELECT 
        avg(cast (QAnswer as decimal)) as 执行
          FROM Table_RESULT
        where paperid in(select paperid from table_paper where PaperClassID=2) and Qid in(1,2,3,4,5,6,7,8)) as a,

        (SELECT 
        avg(cast (QAnswer as decimal)) as 技巧
          FROM Table_RESULT
        where paperid  in(select paperid from table_paper where PaperClassID=2) and Qid in(9,10,11,12,13,14,15)) as b,

        (SELECT 
        avg(cast (QAnswer as decimal)) as 态度
          FROM Table_RESULT
        where paperid in(select paperid from table_paper where PaperClassID=2) and Qid in(16,17,18)) as c,

        (SELECT 
        avg(cast (QAnswer as decimal)) as 能力
          FROM Table_RESULT
        where paperid  in(select paperid from table_paper where PaperClassID=2  ) and Qid in(19,20)) as d");

                    DataSet dsClass1 = objDB.ExecuteDataSet(CommandType.Text, @"select 
        a.q1,
        b.q2,
        c.q3,
        d.q4,
		e.q5,
		f.q6,
		g.q7,
		h.q8
        from

        (SELECT 
        avg(cast (QAnswer as decimal)) as q1
          FROM Table_RESULT
        where paperid in(select paperid from table_paper where teacherid=" + n.ToString() + @" and PaperClassID=2) and qid in(1)) as a,

        (SELECT 
        avg(cast (QAnswer as decimal)) as q2
          FROM Table_RESULT
        where paperid  in(select paperid from table_paper where teacherid = " + n.ToString() + @" and PaperClassID=2) and Qid in(2)) as b,

        (SELECT 
        avg(cast (QAnswer as decimal)) as q3
          FROM Table_RESULT
        where paperid in(select paperid from table_paper where teacherid=" + n.ToString() + @" and PaperClassID=2) and Qid in(3)) as c,

        (SELECT 
        avg(cast (QAnswer as decimal)) as q4
          FROM Table_RESULT
        where paperid  in(select paperid from table_paper where teacherid=" + n.ToString() + @" and PaperClassID=2) and Qid in(4)) as d,

        (SELECT 
        avg(cast (QAnswer as decimal)) as q5
          FROM Table_RESULT
        where paperid in(select paperid from table_paper where teacherid=" + n.ToString() + @" and PaperClassID=2) and Qid in(5)) as e,

        (SELECT 
        avg(cast (QAnswer as decimal)) as q6
          FROM Table_RESULT
        where paperid  in(select paperid from table_paper where teacherid=" + n.ToString() + @" and PaperClassID=2) and Qid in(6)) as f,

        (SELECT 
        avg(cast (QAnswer as decimal)) as q7
          FROM Table_RESULT
        where paperid in(select paperid from table_paper where teacherid=" + n.ToString() + @" and PaperClassID=2) and Qid in(7)) as g,

        (SELECT 
        avg(cast (QAnswer as decimal)) as q8
          FROM Table_RESULT
        where paperid  in(select paperid from table_paper where teacherid=" + n.ToString() + @" and PaperClassID=2) and Qid in(8)) as h");


                    DataSet dsClass1AVG = objDB.ExecuteDataSet(CommandType.Text, @"select 
        a.q1,
        b.q2,
        c.q3,
        d.q4,
		e.q5,
		f.q6,
		g.q7,
		h.q8
        from

        (SELECT 
        avg(cast (QAnswer as decimal)) as q1
          FROM Table_RESULT
        where paperid in(select paperid from table_paper where PaperClassID=2) and qid in(1)) as a,

        (SELECT 
        avg(cast (QAnswer as decimal)) as q2
          FROM Table_RESULT
        where paperid  in(select paperid from table_paper where PaperClassID=2) and Qid in(2)) as b,

        (SELECT 
        avg(cast (QAnswer as decimal)) as q3
          FROM Table_RESULT
        where paperid in(select paperid from table_paper where PaperClassID=2) and Qid in(3)) as c,

        (SELECT 
        avg(cast (QAnswer as decimal)) as q4
          FROM Table_RESULT
        where paperid  in(select paperid from table_paper where PaperClassID=2) and Qid in(4)) as d,

        (SELECT 
        avg(cast (QAnswer as decimal)) as q5
          FROM Table_RESULT
        where paperid in(select paperid from table_paper where PaperClassID=2) and Qid in(5)) as e,

        (SELECT 
        avg(cast (QAnswer as decimal)) as q6
          FROM Table_RESULT
        where paperid  in(select paperid from table_paper where PaperClassID=2) and Qid in(6)) as f,

        (SELECT 
        avg(cast (QAnswer as decimal)) as q7
          FROM Table_RESULT
        where paperid in(select paperid from table_paper where PaperClassID=2) and Qid in(7)) as g,

        (SELECT 
        avg(cast (QAnswer as decimal)) as q8
          FROM Table_RESULT
        where paperid  in(select paperid from table_paper where PaperClassID=2) and Qid in(8)) as h");

                    DataSet dsClass2 = objDB.ExecuteDataSet(CommandType.Text, @"select 
        a.q1,
        b.q2,
        c.q3,
        d.q4,
		e.q5,
		f.q6,
		g.q7
        from

        (SELECT 
        avg(cast (QAnswer as decimal)) as q1
          FROM Table_RESULT
        where paperid in(select paperid from table_paper where teacherid=" + n.ToString() + @" and PaperClassID=2) and Qid in(9)) as a,

        (SELECT 
        avg(cast (QAnswer as decimal)) as q2
          FROM Table_RESULT
        where paperid  in(select paperid from table_paper where teacherid = " + n.ToString() + @" and PaperClassID=2) and Qid in(10)) as b,

        (SELECT 
        avg(cast (QAnswer as decimal)) as q3
          FROM Table_RESULT
        where paperid in(select paperid from table_paper where teacherid=" + n.ToString() + @" and PaperClassID=2) and Qid in(11)) as c,

        (SELECT 
        avg(cast (QAnswer as decimal)) as q4
          FROM Table_RESULT
        where paperid  in(select paperid from table_paper where teacherid=" + n.ToString() + @" and PaperClassID=2) and Qid in(12)) as d,

        (SELECT 
        avg(cast (QAnswer as decimal)) as q5
          FROM Table_RESULT
        where paperid in(select paperid from table_paper where teacherid=" + n.ToString() + @" and PaperClassID=2) and Qid in(13)) as e,

        (SELECT 
        avg(cast (QAnswer as decimal)) as q6
          FROM Table_RESULT
        where paperid  in(select paperid from table_paper where teacherid=" + n.ToString() + @" and PaperClassID=2) and Qid in(14)) as f,

        (SELECT 
        avg(cast (QAnswer as decimal)) as q7
          FROM Table_RESULT
        where paperid in(select paperid from table_paper where teacherid=" + n.ToString() + @" and PaperClassID=2) and Qid in(15)) as g");


                    DataSet dsClass2AVG = objDB.ExecuteDataSet(CommandType.Text, @"select 
        a.q1,
        b.q2,
        c.q3,
        d.q4,
		e.q5,
		f.q6,
		g.q7
        from

        (SELECT 
        avg(cast (QAnswer as decimal)) as q1
          FROM Table_RESULT
        where paperid in(select paperid from table_paper where PaperClassID=2) and Qid in(9)) as a,

        (SELECT 
        avg(cast (QAnswer as decimal)) as q2
          FROM Table_RESULT
        where paperid  in(select paperid from table_paper where PaperClassID=2) and Qid in(10)) as b,

        (SELECT 
        avg(cast (QAnswer as decimal)) as q3
          FROM Table_RESULT
        where paperid in(select paperid from table_paper where PaperClassID=2) and Qid in(11)) as c,

        (SELECT 
        avg(cast (QAnswer as decimal)) as q4
          FROM Table_RESULT
        where paperid  in(select paperid from table_paper where PaperClassID=2) and Qid in(12)) as d,

        (SELECT 
        avg(cast (QAnswer as decimal)) as q5
          FROM Table_RESULT
        where paperid in(select paperid from table_paper where PaperClassID=2) and Qid in(13)) as e,

        (SELECT 
        avg(cast (QAnswer as decimal)) as q6
          FROM Table_RESULT
        where paperid  in(select paperid from table_paper where PaperClassID=2) and Qid in(14)) as f,

        (SELECT 
        avg(cast (QAnswer as decimal)) as q7
          FROM Table_RESULT
        where paperid in(select paperid from table_paper where PaperClassID=2) and Qid in(15)) as g");


                    DataSet dsClass3 = objDB.ExecuteDataSet(CommandType.Text, @"select 
        a.q1,
        b.q2,
        c.q3
        from

        (SELECT 
        avg(cast (QAnswer as decimal)) as q1
          FROM Table_RESULT
        where paperid in(select paperid from table_paper where teacherid=" + n.ToString() + @" and PaperClassID=2) and qid in(16)) as a,

        (SELECT 
        avg(cast (QAnswer as decimal)) as q2
          FROM Table_RESULT
        where paperid  in(select paperid from table_paper where teacherid = " + n.ToString() + @" and PaperClassID=2) and Qid in(17)) as b,

        (SELECT 
        avg(cast (QAnswer as decimal)) as q3
          FROM Table_RESULT
        where paperid in(select paperid from table_paper where teacherid=" + n.ToString() + @"  and PaperClassID=2) and Qid in(18)) as c");


                    DataSet dsClass3AVG = objDB.ExecuteDataSet(CommandType.Text, @"select 
        a.q1,
        b.q2,
        c.q3
        from

        (SELECT 
        avg(cast (QAnswer as decimal)) as q1
          FROM Table_RESULT
        where paperid in(select paperid from table_paper where PaperClassID=2) and qid in(16)) as a,

        (SELECT 
        avg(cast (QAnswer as decimal)) as q2
          FROM Table_RESULT
        where paperid  in(select paperid from table_paper where PaperClassID=2) and Qid in(17)) as b,

        (SELECT 
        avg(cast (QAnswer as decimal)) as q3
          FROM Table_RESULT
        where paperid in(select paperid from table_paper where  PaperClassID=2) and Qid in(18)) as c");


                    DataSet dsClass4 = objDB.ExecuteDataSet(CommandType.Text, @"select 
        a.q1,
        b.q2
        from

        (SELECT 
        avg(cast (QAnswer as decimal)) as q1
          FROM Table_RESULT
        where paperid in(select paperid from table_paper where teacherid=" + n.ToString() + @" and PaperClassID=2) and qid in(19)) as a,

        (SELECT 
        avg(cast (QAnswer as decimal)) as q2
          FROM Table_RESULT
        where paperid  in(select paperid from table_paper where teacherid = " + n.ToString() + @" and PaperClassID=2) and Qid in(20)) as b");


                    DataSet dsClass4AVG = objDB.ExecuteDataSet(CommandType.Text, @"select 
        a.q1,
        b.q2
        from

        (SELECT 
        avg(cast (QAnswer as decimal)) as q1
          FROM Table_RESULT
        where paperid in(select paperid from table_paper where PaperClassID=2) and qid in(19)) as a,

        (SELECT 
        avg(cast (QAnswer as decimal)) as q2
          FROM Table_RESULT
        where paperid  in(select paperid from table_paper where PaperClassID=2) and Qid in(20)) as b");

                    jsnlDS ds = new jsnlDS();

                    string tName = objDB.ExecuteScalar(CommandType.Text, @"select teachername from table_teacher where teacherid=" + n.ToString()).ToString();
                    string tGroup = objDB.ExecuteScalar(CommandType.Text, @"select GroupName from Table_Group where GroupID in (select groupid from table_teacher where teacherid=" + n.ToString()+")").ToString();
                    if (dsAll != null && dsAll.Tables[0].Rows.Count > 0)
                    {
                        ds.jsnlAll.AddjsnlAllRow("执行", dsAll.Tables[0].Rows[0][0].ToString(), tName);
                        ds.jsnlAll.AddjsnlAllRow("技巧", dsAll.Tables[0].Rows[0][1].ToString(), tName);
                        ds.jsnlAll.AddjsnlAllRow("态度", dsAll.Tables[0].Rows[0][2].ToString(), tName);
                        ds.jsnlAll.AddjsnlAllRow("能力", dsAll.Tables[0].Rows[0][3].ToString(), tName);

                        ds.jsnlAll.AddjsnlAllRow("执行", dsAllAVG.Tables[0].Rows[0][0].ToString(), "系统平均值");
                        ds.jsnlAll.AddjsnlAllRow("技巧", dsAllAVG.Tables[0].Rows[0][1].ToString(), "系统平均值");
                        ds.jsnlAll.AddjsnlAllRow("态度", dsAllAVG.Tables[0].Rows[0][2].ToString(), "系统平均值");
                        ds.jsnlAll.AddjsnlAllRow("能力", dsAllAVG.Tables[0].Rows[0][3].ToString(), "系统平均值");
                    }

                    if (dsClass1 != null && dsClass1.Tables[0].Rows.Count > 0)
                    {
                        ds.jsnlClass1.AddjsnlClass1Row("熟悉课程内容，讲解流畅", dsClass1.Tables[0].Rows[0][0].ToString(), tName);
                        ds.jsnlClass1.AddjsnlClass1Row("讲解能够围绕课程主题", dsClass1.Tables[0].Rows[0][1].ToString(), tName);
                        ds.jsnlClass1.AddjsnlClass1Row("能够根据培训目标\r\n完成各课程单元的\r\n讲解，有课程小结", dsClass1.Tables[0].Rows[0][2].ToString(), tName);
                        ds.jsnlClass1.AddjsnlClass1Row("对案例的讲解分析合理恰当", dsClass1.Tables[0].Rows[0][3].ToString(), tName);
                        ds.jsnlClass1.AddjsnlClass1Row("对方法、技巧的示范明了易懂", dsClass1.Tables[0].Rows[0][4].ToString(), tName);
                        ds.jsnlClass1.AddjsnlClass1Row("授课教具准备充分", dsClass1.Tables[0].Rows[0][5].ToString(), tName);
                        ds.jsnlClass1.AddjsnlClass1Row("能够根据课程重难点\r\n合理安排课程讲解\r\n和课堂活动时间", dsClass1.Tables[0].Rows[0][6].ToString(), tName);
                        ds.jsnlClass1.AddjsnlClass1Row("能够准时开课、下课", dsClass1.Tables[0].Rows[0][7].ToString(), tName);


                        ds.jsnlClass1.AddjsnlClass1Row("熟悉课程内容，讲解流畅", dsClass1AVG.Tables[0].Rows[0][0].ToString(), "系统平均值");
                        ds.jsnlClass1.AddjsnlClass1Row("讲解能够围绕课程主题", dsClass1AVG.Tables[0].Rows[0][1].ToString(), "系统平均值");
                        ds.jsnlClass1.AddjsnlClass1Row("能够根据培训目标\r\n完成各课程单元的\r\n讲解，有课程小结", dsClass1AVG.Tables[0].Rows[0][2].ToString(), "系统平均值");
                        ds.jsnlClass1.AddjsnlClass1Row("对案例的讲解分析合理恰当", dsClass1AVG.Tables[0].Rows[0][3].ToString(), "系统平均值");
                        ds.jsnlClass1.AddjsnlClass1Row("对方法、技巧的示范明了易懂", dsClass1AVG.Tables[0].Rows[0][4].ToString(), "系统平均值");
                        ds.jsnlClass1.AddjsnlClass1Row("授课教具准备充分", dsClass1AVG.Tables[0].Rows[0][5].ToString(), "系统平均值");
                        ds.jsnlClass1.AddjsnlClass1Row("能够根据课程重难点\r\n合理安排课程讲解\r\n和课堂活动时间", dsClass1AVG.Tables[0].Rows[0][6].ToString(), "系统平均值");
                        ds.jsnlClass1.AddjsnlClass1Row("能够准时开课、下课", dsClass1AVG.Tables[0].Rows[0][7].ToString(), "系统平均值");
                    }

                    if (dsClass2 != null && dsClass2.Tables[0].Rows.Count > 0)
                    {
                        ds.jsnlClass2.AddjsnlClass2Row("经常提问引导学员学习", dsClass2.Tables[0].Rows[0][0].ToString(), tName);
                        ds.jsnlClass2.AddjsnlClass2Row("经常鼓励学员发言、提问 ", dsClass2.Tables[0].Rows[0][1].ToString(), tName);
                        ds.jsnlClass2.AddjsnlClass2Row("能够活跃课堂气氛、控制课堂秩序 ", dsClass2.Tables[0].Rows[0][2].ToString(), tName);
                        ds.jsnlClass2.AddjsnlClass2Row("能够引导不同学习态度学员，调动全员参与 ", dsClass2.Tables[0].Rows[0][3].ToString(), tName);
                        ds.jsnlClass2.AddjsnlClass2Row("授课语音、语调适当，表达清晰易懂 ", dsClass2.Tables[0].Rows[0][4].ToString(), tName);
                        ds.jsnlClass2.AddjsnlClass2Row("能将个人行业经验与课程讲授的结合 ", dsClass2.Tables[0].Rows[0][5].ToString(), tName);
                        ds.jsnlClass2.AddjsnlClass2Row("能够配合课程内容讲授恰当案例", dsClass2.Tables[0].Rows[0][6].ToString(), tName);

                        ds.jsnlClass2.AddjsnlClass2Row("经常提问引导学员学习", dsClass2AVG.Tables[0].Rows[0][0].ToString(), "系统平均值");
                        ds.jsnlClass2.AddjsnlClass2Row("经常鼓励学员发言、提问 ", dsClass2AVG.Tables[0].Rows[0][1].ToString(), "系统平均值");
                        ds.jsnlClass2.AddjsnlClass2Row("能够活跃课堂气氛、控制课堂秩序 ", dsClass2AVG.Tables[0].Rows[0][2].ToString(), "系统平均值");
                        ds.jsnlClass2.AddjsnlClass2Row("能够引导不同学习态度学员，调动全员参与 ", dsClass2AVG.Tables[0].Rows[0][3].ToString(), "系统平均值");
                        ds.jsnlClass2.AddjsnlClass2Row("授课语音、语调适当，表达清晰易懂 ", dsClass2AVG.Tables[0].Rows[0][4].ToString(), "系统平均值");
                        ds.jsnlClass2.AddjsnlClass2Row("能将个人行业经验与课程讲授的结合 ", dsClass2AVG.Tables[0].Rows[0][5].ToString(), "系统平均值");
                        ds.jsnlClass2.AddjsnlClass2Row("能够配合课程内容讲授恰当案例", dsClass2AVG.Tables[0].Rows[0][6].ToString(), "系统平均值");
                    }

                    if (dsClass3 != null && dsClass3.Tables[0].Rows.Count > 0)
                    {
                        ds.jsnlClass3.AddjsnlClass3Row("授课精神饱满有热情", dsClass3.Tables[0].Rows[0][0].ToString(), tName);
                        ds.jsnlClass3.AddjsnlClass3Row("讲解细致认真", dsClass3.Tables[0].Rows[0][1].ToString(), tName);
                        ds.jsnlClass3.AddjsnlClass3Row("对学员回答问题后的反应积极\r\n（肯定，表扬，启发等）", dsClass3.Tables[0].Rows[0][2].ToString(), tName);

                        ds.jsnlClass3.AddjsnlClass3Row("授课精神饱满有热情", dsClass3AVG.Tables[0].Rows[0][0].ToString(), "系统平均值");
                        ds.jsnlClass3.AddjsnlClass3Row("讲解细致认真", dsClass3AVG.Tables[0].Rows[0][1].ToString(), "系统平均值");
                        ds.jsnlClass3.AddjsnlClass3Row("对学员回答问题后的反应积极\r\n（肯定，表扬，启发等）", dsClass3AVG.Tables[0].Rows[0][2].ToString(), "系统平均值");
                    }

                    if (dsClass4 != null && dsClass4.Tables[0].Rows.Count > 0)
                    {
                        ds.jsnlClass4.AddjsnlClass4Row("对学员提问的解答准确...", dsClass4.Tables[0].Rows[0][0].ToString(), tName);
                        ds.jsnlClass4.AddjsnlClass4Row("讲解有深度，能启发学员...", dsClass4.Tables[0].Rows[0][1].ToString(), tName);

                        ds.jsnlClass4.AddjsnlClass4Row("对学员提问的解答准确...", dsClass4AVG.Tables[0].Rows[0][0].ToString(), "系统平均值");
                        ds.jsnlClass4.AddjsnlClass4Row("讲解有深度，能启发学员...", dsClass4AVG.Tables[0].Rows[0][1].ToString(), "系统平均值");
                    }

                    Image0.ImageUrl = @"~/tmpIMG/" + getRadarChartImg((DataTable)ds.jsnlAll, tName, 0);
                    Image1.ImageUrl = @"~/tmpIMG/" + getRadarChartImg((DataTable)ds.jsnlClass1, tName, 1);
                    Image2.ImageUrl = @"~/tmpIMG/" + getRadarChartImg((DataTable)ds.jsnlClass2, tName, 2);
                    Image3.ImageUrl = @"~/tmpIMG/" + getRadarChartImg((DataTable)ds.jsnlClass3, tName, 3);
                    Image4.ImageUrl = @"~/tmpIMG/" + getRadarChartImg((DataTable)ds.jsnlClass4, tName, 4);

                    lblTitile.Text = "讲师能力雷达图";
                    lblTDet.Text = tGroup;
                    lblTName.Text = tName;
                    
                    Label6.Text = gettopTname(1);
                    Label7.Text = gettopTname(2);
                    Label8.Text = gettopTname(3);
                    Label9.Text = gettopTname(4);
                    Label10.Text = gettopTname(5);
                    Label11.Text = gettopTname(6);
                    Label12.Text = gettopTname(7);
                    Label13.Text = gettopTname(8);
                    Label14.Text = gettopTname(9);
                    Label15.Text = gettopTname(10);
                    Label16.Text = gettopTname(11);
                    Label17.Text = gettopTname(12);
                    Label18.Text = gettopTname(13);
                    Label19.Text = gettopTname(14);
                    Label20.Text = gettopTname(15);
                    Label21.Text = gettopTname(16);
                    Label22.Text = gettopTname(17);
                    Label23.Text = gettopTname(17);
                    Label24.Text = gettopTname(19);
                    Label25.Text = gettopTname(20);
                    
                    //ReportDataSource rds0 = new ReportDataSource("jsnlAll", (DataTable)ds.jsnlAll);
                    //ReportDataSource rds1 = new ReportDataSource("jsnlClass1", (DataTable)ds.jsnlClass1);
                    //ReportDataSource rds2 = new ReportDataSource("jsnlClass2", (DataTable)ds.jsnlClass2);
                    //ReportDataSource rds3 = new ReportDataSource("jsnlClass3", (DataTable)ds.jsnlClass3);
                    //ReportDataSource rds4 = new ReportDataSource("jsnlClass4", (DataTable)ds.jsnlClass4);

                    //ReportParameter p1 = new ReportParameter("tNm", tName);
                   
                    //ReportViewer1.LocalReport.DataSources.Add(rds0);
                    //ReportViewer1.LocalReport.DataSources.Add(rds1);
                    //ReportViewer1.LocalReport.DataSources.Add(rds2);
                    //ReportViewer1.LocalReport.DataSources.Add(rds3);
                    //ReportViewer1.LocalReport.DataSources.Add(rds4);
                    //ReportViewer1.LocalReport.SetParameters(p1);

                    //ReportViewer1.LocalReport.Refresh();
                }
                catch (Exception ex)
                {
                    Response.Write(ex.Message);
                }
            }
        }

        private string gettopTname(int qid)
        {
            string ret = string.Empty;
            Database objDB = new SqlDatabase(M_CONSTR);
            Object o = objDB.ExecuteScalar(CommandType.Text, @"select teachername from table_teacher where teacherid in(
select teacherid from Table_PAPER where paperid in(
select t.paperid from(

select top 1 sum(convert(int,aa.qanswer)) as score, aa.paperid from 
(select  qanswer, paperid from Table_RESULT  where qid="+qid.ToString()+
@" and paperid in (select paperid from Table_PAPER where PaperClassID=2)) aa
group by paperid order by score desc

) t))");
            if (o != null) ret = o.ToString();
            return ret;
        }

        private void releaseObject(object obj)
        {
            try
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
                obj = null;
            }
            catch (Exception ex)
            {
                obj = null;
                Response.Write(ex.Message);
            }
            finally
            {
                GC.Collect();
            }
        }

        private string getRadarChartImg(DataTable dt, string tNm, int rangeType)
        {
            if (dt == null || dt.Rows.Count == 0)
            {
                return null;
            }
            else
            {
                foreach (DataRow dr in dt.Rows)
                {
                    //保留两位小数
                    dr["得分"] = decimal.Round(decimal.Parse(dr["得分"].ToString()), 2);
                }

                Excel.Application xlApp;
                Excel.Workbook xlWorkBook;
                Excel.Worksheet xlWorkSheet;
                object misValue = System.Reflection.Missing.Value;

                xlApp = new Excel.Application();
                xlWorkBook = xlApp.Workbooks.Add(misValue);
                xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

                xlWorkSheet.Cells[1, 1] = "";

                for (int j = 0; j < dt.Rows.Count / 2; j++)
                {
                    string str = dt.Rows[j][0].ToString();
                    xlWorkSheet.Cells[1, j+2] = str;  
                }

                xlWorkSheet.Cells[2, 1] = tNm;
                xlWorkSheet.Cells[3, 1] = "系统平均值";

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    int col = i;
                    int row = 2;

                    if (i >= dt.Rows.Count / 2)
                    {
                        row = 3;
                        col = i - (dt.Rows.Count / 2);
                    }
                    string str = dt.Rows[i][1].ToString();
                    xlWorkSheet.Cells[row, col + 2] = str;
                }

                Excel.Range chartRange;

                Excel.ChartObjects xlCharts = (Excel.ChartObjects)xlWorkSheet.ChartObjects(Type.Missing);
                Excel.ChartObject myChart = (Excel.ChartObject)xlCharts.Add(10, 80, 400, 300);
                Excel.Chart chartPage = myChart.Chart;

                string s = "";
                string e = "";

                if (rangeType == 0)
                {
                    s = "A1";
                    e = "e3";
                }
                else if (rangeType == 1)
                {
                    s = "A1";
                    e = "i3";
                }
                else if (rangeType == 2)
                {
                    s = "A1";
                    e = "h3";
                }
                else if (rangeType == 3)
                {
                    s = "A1";
                    e = "d3";
                }
                else if (rangeType == 4)
                {
                    s = "A1";
                    e = "c3";
                }

                chartRange = xlWorkSheet.get_Range(s,e);
                chartPage.SetSourceData(chartRange, misValue);

                chartPage.ChartType = Excel.XlChartType.xlRadar;
                if (rangeType == 4)
                {
                    chartPage.ChartType = Excel.XlChartType.xlColumnClustered;
                    Excel.ChartGroup grp = (Excel.ChartGroup)chartPage.ChartGroups(1);

                    Excel.Series ser = (Excel.Series)grp.SeriesCollection(1);
                    Excel.Series ser2 = (Excel.Series)grp.SeriesCollection(2);
                    ser.HasDataLabels = true;
                    ser2.HasDataLabels = true;

                }

                string fileNM =  Guid.NewGuid().ToString() + ".bmp";

                chartPage.Export(Server.MapPath("~/tmpIMG/")+fileNM, "BMP", misValue);

                System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath("~/tmpIMG/") + fileNM);
                Graphics g = Graphics.FromImage(image);
              
                xlWorkBook.SaveAs(Server.MapPath("~/tmpIMG/")+fileNM + ".xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
                xlWorkBook.Close(true, misValue, misValue);
                xlApp.Quit();

                releaseObject(xlWorkSheet);
                releaseObject(xlWorkBook);
                releaseObject(xlApp);

                //System.IO.File.Delete(fileNM + ".xls");

                return fileNM;
            }
        }
    }
}